登录mysql查看当前数据存储目录
mysql -uroot -p
mysql> select @@datadir;
+-----------------+
| @@datadir |
+-----------------+
| /var/lib/mysql/ |
+-----------------+
1 row in set (0.00 sec)
关闭mysql-server
sudo systemctl stop mysql
确认的确关闭mysql-server
sudo systemctl status mysql
关闭无误,输出类似 "Jul 18 11:24:20 ubuntu-512mb-nyc1-01 systemd[1]: Stopped MySQL Community Server."
转移数据目录
sudo rsync -av /var/lib/mysql /data/
备份源数据
sudo mv /var/lib/mysql /var/lib/mysql.bak
sudo mkdir /var/lib/mysql/mysql -p
sudo mkdir /var/lib/mysql/mysql -p 是为了保证 /usr/share/mysql/mysql-systemd-start 中验证目录正确
修改mysql-server配置 /etc/mysql/mysql.conf.d/mysqld.cnf
datadir=/data/mysql
AppArmor权限修改 追加以下内容到 /etc/apparmor.d/tunables/alias
alias /var/lib/mysql/ -> /data/mysql/,
重启AppArmor
sudo systemctl restart apparmor
没有追加alias内容,可能导致
<pre>
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service"
and "journalctl -xe" for details.
</pre>
启动mysql-server
sudo systemctl start mysql
sudo systemctl status mysql
原文链接
https://www.digitalocean.com/...
欢迎您加入我们的专属QQ讨论群组① 233415606 ② 233415756
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。